# basic windows of editor by override QWidget
# gray grid 


from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from node_graphics_scene import NodeEditorScene

class NodeEditorWin(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.initUI()
    
    def initUI(self):
        self.setGeometry(400,200,1200,1000)   # Widget Size

        # doc.qt.io/qt-5/examples-graphicsview.html
        self.layout = QVBoxLayout()
        self.layout.setContentsMargins(0,0,0,0)  # margin distance
        self.setLayout(self.layout)

        # create graphics scene
        #self.grScene = QGraphicsScene()
        self.grScene = NodeEditorScene()
        # create graphics view
        #self.view = QGraphicsView(self)
        #self.view.setScene(self.grScene)
        self.view = NodeEditorView(self.grScene,self)
        self.layout.addWidget(self.view)


        self.setWindowTitle("Node Editor")
        self.show()



        self.addDebugContent()

    def addDebugContent(self):
        greenBrush = QBrush(Qt.green)
        outlinePen = QPen(Qt.black)
        outlinePen.setWidth(2)

        #TODO gridSize 数值为40时，拖动会让drawLines dark出现参数不足导致闪退
        rect = self.grScene.addRect(0,0,100,100, outlinePen, greenBrush)
        rect.setFlag(QGraphicsItem.ItemIsMovable)

        text = self.grScene.addText("text",QFont("Ubuntu"))
        text.setFlag(QGraphicsItem.ItemIsSelectable) 
        text.setFlag(QGraphicsItem.ItemIsMovable) # lines_dark会闪退
        text.setDefaultTextColor(QColor.fromRgbF(1.0,1.0,1.0))

        widget1 = QPushButton("Button")
        widget2 = QTextEdit()
        btn = self.grScene.addWidget(widget1)
        btn.setPos(0,30)
        edit = self.grScene.addWidget(widget2)
        edit.setPos(0,60)

        line = self.grScene.addLine(-100,-100,400,200,outlinePen)
        #line.setFlag(QGraphicsItem.ItemIsSelectable)
        line.setFlag(QGraphicsItem.ItemIsMovable)


